﻿using FollowMe.Services;
using FollowMe.Services.Request;
using Microsoft.Practices.Unity;
using System.Web.Http;
using System.Web.Http.ModelBinding;
using FollowMe.Services.Response;

namespace FollowMe.API.Controllers
{
    /// <summary>
    /// Google Cloud Messaging Related API functions
    /// </summary>
    [RoutePrefix("api/GCM")]
    public class GCMController : ApiController
    {
        /// <summary>
        /// The _services
        /// </summary>
        private IFollowMeService _services;

        /// <summary>
        /// Initializes a new instance of the <see cref="GCMController"/> class.
        /// </summary>
        public GCMController()
        {
        }

        /// <summary>
        /// Initializes a new instance of the <see cref="GCMController"/> class.
        /// </summary>
        /// <param name="services">The services.</param>
        [InjectionConstructor]
        public GCMController(FollowMeService services)
        {
            _services = services;
        }


        //POST api/GCM/Register
        /// <summary>
        /// Registers the specified request.
        /// </summary>
        /// <param name="request">The request.</param>
        /// <returns>The GCM commit results</returns>
        [Route("Register", Name = "Register")]
        [AllowAnonymous]
        [System.Web.Http.AcceptVerbs("POST")]
        [System.Web.Http.HttpPost]
        public IHttpActionResult Register(AddRegistrationIDRequest request)
        {
            if (!ModelState.IsValid)
            {
                return BadRequest("Bad model");
            }

            HTTPResults result = _services.addRegistrationID(request);

            if (result.success == true) return Ok(result); else return BadRequest(result.statustext);;
        }

    }
}